﻿
@{
    ViewBag.Title = "评论列表";
}
@section CSS{

}
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            评论
            <small>列表</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li><a href="#">商品管理</a></li>
            <li class="active">评论列表</li>
        </ol>
    </section>
    <section>
        <div class="col-xs-12">
            <div class="box box-primary ">
                <!-- form start -->
                <form class="form-horizontal">
                    <div class="box-body">
                        <div class="form-group">
                            <label for="status" class="col-sm-2 control-label">状态</label>
                            <div class="col-sm-2">
                                <select class="form-control" id="status">
                                    <option value="-1">-请选择状态-</option>
                                    <option value="0">未审核</option>
                                    <option value="1">审核通过</option>
                                    <option value="2">审核失败</option>
                                </select>
                            </div>
                            <label  class="col-sm-2 control-label">评论日期</label>
                            <div class="col-sm-2">
                                <div class="input-group date">
                                    <div class="input-group-addon">
                                        <i class="fa fa-calendar"></i>
                                    </div>
                                    <input type="text" class="form-control pull-right" id="startTime">
                                </div>
                            </div>
                            <label style="float:left;"> - </label>
                            <div class="col-sm-2">
                                <div class="input-group date">
                                    <div class="input-group-addon">
                                        <i class="fa fa-calendar"></i>
                                    </div>
                                    <input type="text" class="form-control pull-right" id="endTime">
                                </div>
                            </div>
                        </div>
                    </div>
                        <!-- /.box-body -->
                        <div class="box-footer ">
                            <button type="button" class="btn btn-primary btn-search center-block" id="btnSearch"><i class="fa fa-search"></i> 查询</button>
                            @*<button type="button" class="btn btn-danger" id="btnDelMul"><i class="fa fa-remove"></i> 批量删除</button>
                                <button type="button" class="btn btn-info" id="btnAdd"><i class="fa fa-plus"></i> 添加</button>
                                <button type="button" class="btn btn-success" id="btnExport"><i class="fa fa-download"></i> 导出Excel</button>*@
                        </div>
                        <!-- /.box-footer -->
                </form>
            </div>
        </div>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    @*<div class="box-header">
                            &nbsp;
                        </div>*@
                    <!-- /.box-header -->
                    <div class="box-body">
                        <table id="DataList" class="table table-bordered table-striped table-hover ">
                            <thead>
                                <tr>
                                    <th>编号</th>
                                    <th>订单编号</th>
                                    <th>商品编号</th>
                                    <th>排序</th>
                                    <th>是否匿名</th>
                                    <th width="50px">用户名/昵称</th>
                                    <th>商品描述<br />评分</th>
                                    <th>商家态度<br />评分</th>
                                    <th>物流服务<br />评分</th>
                                    <th width="90px">评论</th>
                                    <th width="90px">回复</th>
                                    <th>点赞数</th>
                                    <th>反对数</th>
                                    <th>评论时间</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody> </tbody>
                        </table>
                    </div>
                    <!-- /.box-body -->
                </div>
                <!-- /.box -->
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->
    </section>
    <!-- /.content -->
</div>
<!-- /.content-wrapper -->
@section JS{
    <script>
        $(function () {
            //初始化表格
            GenerateTable();
            //鼠标移动到该行变色
            $('.table-hover tbody').on('click', 'tr', function () {
                if ($(this).hasClass('selected')) {
                    $(this).removeClass('selected');
                }
                else {
                    u_table.$('tr.selected').removeClass('selected');
                    $(this).addClass('selected');
                }
            });
            //搜索事件
            $("#btnSearch").on("click", function () {
                var classSelect = $("#classSelect").val();
                var datemin = $('#startTime').val();
                var datemax = $("#endTime").val();
                if ((datemin == null && datemax != null) || (datemin != null && datemax == null)) {
                    layer.msg('请把时间填充完整!', { icon: 1, time: 1000 });
                }
                else {
                    u_table.fnDestroy();
                    GenerateTable();
                }
            });

            $('#startTime').datepicker({
                autoclose: true
            });

            $('#endTime').datepicker({
                autoclose: true
            });
        });
        //生成表格
        function GenerateTable() {
            u_table = $('#DataList').dataTable({
                "lengthChange": true,
                "searching": false,
                "ordering": false,
                "iDisplayLength": 10,
                "bProcessing": true,
                "bServerSide": true,
                "fnServerParams": function (aoData) {
                    var status = $("#status").val();
                    var datemin = $('#startTime').val();
                    var datemax = $("#endTime").val();
                    aoData.push(
                        { "name": "dateMin", "value": datemin },
                        { "name": "dateMax", "value": datemax },
                        { "name": "status", "value": status }
                    );
                },
                "sAjaxSource": "/goods/Commentlist",
                "aoColumns": [
                    { "mDataProp": 'id' },
                    { "mDataProp": 'order_goods_id' },
                    { "mDataProp": 'goods_id' },
                    { "mDataProp": 'sort' },
                     {
                         "mDataProp": 'is_anonymity', "mRender": function (data, type, full) {
                             return data ? "是" : "否";
                         }
                     },
                    { "mDataProp": 'nick_name' },
                    { "mDataProp": 'description_mark' },
                    { "mDataProp": 'attitude_mark' },
                    { "mDataProp": 'logistics_mark' },
                     { "mDataProp": 'review' },
                    { "mDataProp": 'reply' },
                    { "mDataProp": 'yes_total' },
                    { "mDataProp": 'no_total' },
                    {
                        "mDataProp": 'add_time', "mRender": function (data, type, full) {
                            return moment(data).format("YYYY-MM-DD HH:mm:ss");
                        }
                    },
                    {
                        "mDataProp": 'status', "mRender": function (data, type, full) {
                            return data == 0 ? "审核中" : (data == 1 ? "审核通过" : "审核失败");
                        }
                    },
                    {
                        "mDataProp": 'id', "mRender": function (data, type, full) {
                            if (full. status== 0) {
                                return '<a style="text-decoration:none" class="btn btn-success" onClick="comment_pass(this,' + full.id + ')" href="javascript:;" title="点击审核失败">通过</a>'
                                + '<a style="text-decoration:none" class="btn btn-danger" onClick="comment_noPass(this,' + full.id + ')" href="javascript:;" title="点击审核失败">禁用</a>';
                            } else if (full.status == 1) {
                                return '<a style="text-decoration:none" class="btn btn-danger" onClick="comment_noPass(this,' + full.id + ')" href="javascript:;" title="点击审核失败">禁用</a>';
                            }
                            else {
                                return '<a style="text-decoration:none" class="btn btn-success" onClick="comment_pass(this,' + full.id + ')" href="javascript:;" title="点击审核失败">通过</a>';
                            }

                            //return '<a  class="btn btn-default" onClick="comment_del(this,' + data + ')" href="javascript:;" title="删除"><i class="fa  fa-remove"></i></a>';
                        }
                    }
                ]
            });
        }

        /*审核*/
        function comment_pass(obj, id) {
            layer.confirm('确定审核通过？', function (index) {
                $.ajax({
                    type: "post",
                    url: "/goods/SetCommentIsUse",
                    dataType: "json",
                    data: { id: id, isUse: 1 },
                    success: function (data) {
                        if (data.status == "y") {
                            layer.msg('审核通过', { icon: 6, time: 1000 },
                                function () {
                                    window.location.href = "/goods/comment";
                                });
                        }
                        else {
                            layer.msg(data.info, { icon: 5, time: 1000 });
                        }
                    }
                });

            });
        }
        /*审核不通过*/
        function comment_noPass(obj, id) {
            layer.confirm('确定审核不通过？', function (index) {
                $.ajax({
                    type: "post",
                    url: "/goods/SetCommentIsUse",
                    dataType: "json",
                    data: { id: id, isUse: 2 },
                    success: function (data) {
                        if (data.status == "y") {
                            layer.msg('操作成功', { icon: 6, time: 1000 },
                                function () {
                                    window.location.href = "/goods/comment";
                                });
                        }
                        else {
                            layer.msg(data.info, { icon: 5, time: 1000 });
                        }
                    }
                });

            });
        }

    </script>
}
